//
//  JinengXuanViewController.m
//  XRSquare
//
//  Created by 穆相臣 on 2018/8/22.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "JinengXuanViewController.h"

@interface JinengXuanViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView * contentTableView;
    NSArray * dataArrr;
}

@end

@implementation JinengXuanViewController

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
    {
        
    }
    return self;
}

-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.tintColor = [UIColor grayColor];
    self.navigationItem.title = @"选择技能";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    
    CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
    CGRect rectNav = self.navigationController.navigationBar.frame;
    
    contentTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, rectStatus.size.height + rectNav.size.height, ScreenWidth, ScreenHeight - rectStatus.size.height - rectNav.size.height) style:UITableViewStylePlain];
    contentTableView.delegate = self;
    contentTableView.dataSource = self;
    contentTableView.tableFooterView = [UIView new];
    [self.view addSubview:contentTableView];
    
    [self request];
}

-(void)request
{
    
    [NetRequestCenter soldabilityResult:^(BOOL success, NSDictionary *resultDic) {
        if (success)
        {
            dataArrr = [[resultDic objectForKey:@"data"]objectForKey:@"CouldSold"];
            [contentTableView reloadData];
        }
    }];
}


#pragma mark - tableview

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [dataArrr count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identifer = @"identifer";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifer];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
    }
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.text = [[dataArrr objectAtIndex:indexPath.row]objectForKey:@"Name"];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.delegate jinengXuanId:[[dataArrr objectAtIndex:indexPath.row] objectForKey:@"Name"] jinengid:[[dataArrr objectAtIndex:indexPath.row]  objectForKey:@"LevelId"]];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
